/*
 * VHTabPanelRRCupRound.java
 * Created on 16 août 2009
 *
 * VirtualHockey Internet Platform
 * http://code.google.com/p/virtualhockey/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */

package com.hockeo.vhweb.client.ui.panels;

import java.util.List;

import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TabPanelEvent;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.hockeo.vhweb.client.mvc.VHController;
import com.hockeo.vhweb.client.rpc.VHRpcResultReceiver;
import com.hockeo.vhweb.client.ui.base.VHTabItem;
import com.hockeo.vhweb.client.ui.tabs.VHLeagueStandingsTab;
import com.hockeo.vhweb.client.utils.VHJsData;

/**
 * Panel for round robin cup contest rounds. Lists a tab for each round robin contest
 * element.
 *
 * @version $Id$
 * @author jjanke
 */
public class VHTabPanelRRCupRound extends TabPanel implements VHRpcResultReceiver<List<VHJsData>>
{
  private VHController d_controller;

  /**
   * Builds a new VHTabPanelLeague.
   *
   * @param league the model identifying the league to be represented
   */
  public VHTabPanelRRCupRound( VHController controller )
  {
    d_controller = controller;

    setBorders( false );
    setAutoWidth( true );
    setDeferHeight( true );
    setTabScroll( true );

    // Add event listener to make sure the tabs have their content built when they are
    // shown for the first time.
    //
    addListener( Events.Select, new Listener<TabPanelEvent>() {
      public void handleEvent( TabPanelEvent evt )
      {
        ( (VHTabItem) evt.getItem() ).buildContent();
        ( (VHTabItem) evt.getItem() ).layout();
      }
    } );
  }

  /**
   * Loads the different contest elements for which tab items should be shown.
   */
  public void setRpcData( List<VHJsData> result, String strPurpose )
  {
    // remove all previously existing contest element tabs
    //
    removeAll();

    // Tabs
    //
    TabItem tabItem;

    for ( VHJsData element : result )
    {
      tabItem = new VHLeagueStandingsTab( d_controller, element );
      add( tabItem );
    }
  }
}
